package com.suneee.refund.service.impl;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.suneee.base.util.ContextHelper;
import com.suneee.context.page.Page;
import com.suneee.core.error.Assert;
import com.suneee.refund.bean.FinancialOfflineInfoSearchBean;
import com.suneee.refund.dao.FinancialOfflineInfoDao;
import com.suneee.refund.entity.FinancialOfflineInfo;
import com.suneee.refund.service.FinancialOfflineInfoService;

@Service("api-financialOfflineInfo")
public class FinancialOfflineInfoServiceImpl implements FinancialOfflineInfoService {

	@Autowired
	private FinancialOfflineInfoDao financialOfflineInfoDao;

	@Override
	public void addFinancialOfflineInfo(FinancialOfflineInfo financialOfflineInfo) {
		Assert.notNull(financialOfflineInfo.getType(), "登记类型");
		Assert.notNull(financialOfflineInfo.getOrderId(), "订单编号");
		Assert.notNull(financialOfflineInfo.getOutFee(), "转出金额");
		Assert.notNull(financialOfflineInfo.getSpuCode(), "商品编码");
		Assert.notNull(financialOfflineInfo.getSpuName(), "商品名称");
		Assert.notNull(financialOfflineInfo.getOutTimeTemp(), "转出时间");
		Assert.notNull(financialOfflineInfo.getBuyerAccount(), "买家账号");
		Timestamp timestamp = new Timestamp(System.currentTimeMillis());
		String enterpriseCode = ContextHelper.getCurrentLoginInfo().getEnterprise().getEnterpriseCode();
		financialOfflineInfo.setCreatedAt(timestamp);
		financialOfflineInfo.setUpdatedAt(timestamp);
		// 企业编码
		financialOfflineInfo.setEnterpriseCode(enterpriseCode);
		financialOfflineInfo.setOutTime(new Timestamp(financialOfflineInfo.getOutTimeTemp()));
		// 用户id
		financialOfflineInfo.setOptUserId(ContextHelper.getCurrentLoginInfo().getAdminId());
		financialOfflineInfoDao.insert(financialOfflineInfo);
	}

	@Override
	public void deleteFinancialOfflineInfo(int id) {
		Assert.notNull(id, "主键id");
		financialOfflineInfoDao.delete(id);
	}

	@Override
	public Page<FinancialOfflineInfo> getRecordedList(FinancialOfflineInfoSearchBean bean) {
		if (bean ==null) {
			bean = new FinancialOfflineInfoSearchBean();
		}
		String enterpriseCode = ContextHelper.getCurrentLoginInfo().getEnterprise().getEnterpriseCode();
		bean.setEnterpriseCode(enterpriseCode);
		return financialOfflineInfoDao.findFinancialOfflineInfo(bean);
	}

	@Override
	public FinancialOfflineInfo getFinancialOfflineInfo(int id) {
		Assert.notNull(id, "主键id");
		return financialOfflineInfoDao.select(id);
	}

	@Override
	public List<FinancialOfflineInfo> listEnterpriseFinancialOfflineInfo() {
		String enterpriseCode = ContextHelper.getCurrentLoginInfo().getEnterprise().getEnterpriseCode();
		return financialOfflineInfoDao.listEnterpriseFinancialOfflineInfo(enterpriseCode);
	}

}
